{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "using SymPy\n",
    "using LinearAlgebra"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 旋量度规的确定\n",
    "\n",
    "【确定依据】：**旋量度规在自旋变换的作用下不变**\n",
    "\n",
    "#### 1）自旋矩阵的约束\n",
    "\n",
    "自旋矩阵$L^\\Sigma_{\\ \\ \\Omega}\\in \\mathrm{SU}(2)$:\n",
    "\n",
    "$$L^\\dagger L=I,\\quad \\det L=1$$\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\[\\left[ \\begin{array}{rr}a&b\\\\c&d\\end{array}\\right]\\]"
      ],
      "text/plain": [
       "2×2 Array{Sym,2}:\n",
       " a  b\n",
       " c  d"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@vars a b c d\n",
    "\n",
    "L=[a b; c d]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "约束条件1： $ \\det L=1$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "a*d => b*c + 1"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cond1 = solve(det(L)-1,[a*d]);\n",
    "cond1 = a*d=>cond1[1]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "约束条件2：$L^\\dagger L=I$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(c => -conjugate(b), d => conjugate(a))"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# L的逆矩阵（带入条件1）\n",
    "Li= L |> inv .|> (expr->expr(cond1));\n",
    "\n",
    "# L的共轭转置\n",
    "Lc = L.T  .|> conj;\n",
    "\n",
    "eqs1 = Li-Lc;\n",
    "eqs1 = [eqs1[i] for i in 1:4];\n",
    "cond2 = solve(eqs1,[c,d])[1];\n",
    "cond2 = c=>cond2[1],d=>cond2[2]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "####  2）旋量度规在自旋变换的作用下不变\n",
    "\n",
    "$$\\epsilon_{AB} L^A_{\\ \\ C}L^B_{\\ \\ D}= \\epsilon_{CD}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\[ \\left[ \\begin{array}{r}a^{2} α - a β \\overline{b} - a γ \\overline{b} - α + ζ \\overline{b}^{2}\\\\a b α - b β \\overline{b} - b γ \\overline{b} - ζ \\overline{a} \\overline{b}\\\\a b α - b β \\overline{b} - b γ \\overline{b} - ζ \\overline{a} \\overline{b}\\\\b^{2} α + b β \\overline{a} + b γ \\overline{a} + ζ \\overline{a}^{2} - ζ\\end{array} \\right] \\]"
      ],
      "text/plain": [
       "4-element Array{Sym,1}:\n",
       "        a^2*α - a*β*conjugate(b) - a*γ*conjugate(b) - α + ζ*conjugate(b)^2\n",
       " a*b*α - b*β*conjugate(b) - b*γ*conjugate(b) - ζ*conjugate(a)*conjugate(b)\n",
       " a*b*α - b*β*conjugate(b) - b*γ*conjugate(b) - ζ*conjugate(a)*conjugate(b)\n",
       "        b^2*α + b*β*conjugate(a) + b*γ*conjugate(a) + ζ*conjugate(a)^2 - ζ"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@vars α β γ ζ\n",
    "\n",
    "# 待定变量\n",
    "ϵ=[α β; γ ζ];\n",
    "\n",
    "\n",
    "# 列方程\n",
    "eqs=[sum(ϵ[A,B]*L[A,C]*L[B,D] for A in 1:2, B in 1:2)-ϵ[C,D] for C in 1:2, D in 1:2];\n",
    "eqs = eqs .|> (expr->expr(cond1)) .|> expand .|> (expr->expr(cond2[1],cond2[2])) .|> simplify;\n",
    "eqs = [eqs[i] for i in 1:4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Dict{Any,Any} with 3 entries:\n",
       "  β => -γ\n",
       "  ζ => 0\n",
       "  α => 0"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 解方程\n",
    "solve(eqs,[α,β,γ,ζ])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 时空度规和旋量度规\n",
    "\n",
    "$$g_{\\mu\\upsilon}=\\mathrm{det}(-1,1,1,1)\\\\ g^{\\mu\\upsilon}=\\mathrm{det}(-1,1,1,1)\\\\ \\delta^\\mu_\\upsilon=\\det (1,1,1,1)$$\n",
    "\n",
    "$$\\epsilon_{\\Sigma\\Omega}=\\epsilon^{\\Sigma\\Omega}=\\begin{pmatrix} 0 & 1 \\\\  -1& 0 \\end{pmatrix}\\\\ \\bar{\\epsilon}_{\\Sigma'\\Omega'}=\\bar{\\epsilon}^{\\Sigma'\\Omega'}=\\begin{pmatrix} 0 & 1 \\\\  -1 & 0 \\end{pmatrix}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "δ = sympy.eye(4); \n",
    "\n",
    "g = sympy.diag(-1, 1, 1, 1);\n",
    "gi = inv(g);\n",
    "\n",
    "ϵ = sympy.Matrix([0 1; -1 0]);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 变换的行列式\n",
    "\n",
    "$$\\det(L)=\\frac{1}{2}\\epsilon_{AB}\\epsilon^{CD}L^A_{\\ \\ C}L^B_{\\ \\ D}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\[ \\left[ \\begin{array}{r}a d - b c\\end{array} \\right] \\]"
      ],
      "text/plain": [
       "1-element Array{Sym,1}:\n",
       " a*d - b*c"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[sum(ϵ[A,B]*ϵ[C,D]*L[A,C]*L[B,D]//2 for A in 1:2, B in 1:2, C in 1:2, D in 1:2)]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 旋量度规的性质\n",
    "\n",
    "\n",
    "#### 1）性质1：\n",
    "\n",
    "$$\\epsilon^A_{\\ \\ C}=\\epsilon^{AB}\\epsilon_{BC}=-\\delta^A_C =\\omicron^A\\iota_C-\\iota^A\\omicron_C\\\\ \\epsilon^\\Sigma_{\\ \\ \\Omega}=\\begin{pmatrix} 0 & 1 \\\\ -1 & 0 \\end{pmatrix}$$\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\[\\left[ \\begin{array}{rr}-1&0\\\\0&-1\\end{array}\\right]\\]"
      ],
      "text/plain": [
       "2×2 Array{Sym,2}:\n",
       " -1   0\n",
       "  0  -1"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[sum(ϵ[A,B]*ϵ[B,C] for B in 1:2) for A in 1:2, C in 1:2] # |> println"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 2) 性质2：\n",
    "\n",
    "$$\\epsilon_{AB}=\\epsilon^{CD}\\epsilon_{CA}\\epsilon_{DB}$$\n",
    "\n",
    "$$\\bar{\\epsilon}_{A'B'}=\\bar{\\epsilon}^{C'D'}\\bar{\\epsilon}_{C'A'}\\bar{\\epsilon}_{D'B'}$$\n",
    "\n",
    "$$\\bar{\\epsilon}^{A'B'}\\bar{\\epsilon}_{B'C'}=-\\delta^A_C$$\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\[\\left[ \\begin{array}{rr}0&1\\\\-1&0\\end{array}\\right]\\]"
      ],
      "text/plain": [
       "2×2 Array{Sym,2}:\n",
       "  0  1\n",
       " -1  0"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[sum(ϵ[C,D]*ϵ[C,A]*ϵ[D,B] for C in 1:2, D in 1:2) for A in 1:2, B in 1:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\[\\left[ \\begin{array}{rr}0&1\\\\-1&0\\end{array}\\right]\\]"
      ],
      "text/plain": [
       "2×2 Array{Sym,2}:\n",
       "  0  1\n",
       " -1  0"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[sum(ϵ[C1,D1]ϵ[C1,A1]ϵ[D1,B1] for C1 in 1:2, D1 in 1:2) for A1 in 1:2, B1 in 1:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\[\\left[ \\begin{array}{rr}-1&0\\\\0&-1\\end{array}\\right]\\]"
      ],
      "text/plain": [
       "2×2 Array{Sym,2}:\n",
       " -1   0\n",
       "  0  -1"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[sum(ϵ[A1,B1]*ϵ[B1,C1] for B1 in 1:2) for A1 in 1:2, C1 in 1:2]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 泡利矩阵及其连带矩阵\n",
    "\n",
    "$$\\sigma_\\mu^{\\ \\ AA'}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2×2×4 Array{Sym,3}:\n",
       "[:, :, 1] =\n",
       " 0.707106781186548                  0\n",
       "                 0  0.707106781186548\n",
       "\n",
       "[:, :, 2] =\n",
       "                 0  0.707106781186548\n",
       " 0.707106781186548                  0\n",
       "\n",
       "[:, :, 3] =\n",
       "                   0  -0.707106781186548*I\n",
       " 0.707106781186548*I                     0\n",
       "\n",
       "[:, :, 4] =\n",
       " 0.707106781186548                   0\n",
       "                 0  -0.707106781186548"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "σ_0 = sympy.Matrix([1 0;0 1])*sqrt(1//2);\n",
    "σ_1 = sympy.Matrix([0 1;1 0])*sqrt(1//2);\n",
    "σ_2 = sympy.Matrix([0 -IM;IM 0])*sqrt(1//2);\n",
    "σ_3 = sympy.Matrix([1 0;0 -1])*sqrt(1/2);\n",
    "σ=[σ_0,σ_1,σ_2,σ_3];\n",
    "σ=[σ[i][j,k] for i in 1:4,j in 1:2 ,k in 1:2];\n",
    "[σ[i,j,k] for j in 1:2 ,k in 1:2,  i in 1:4]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\\sigma^\\mu_{\\ \\ AA'}=g^{\\mu\\upsilon}\\sigma_\\upsilon^{\\ \\ BB'}\\epsilon_{BA}\\bar{\\epsilon}_{B'A'}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2×2×4 Array{Sym,3}:\n",
       "[:, :, 1] =\n",
       " 0.707106781186548                  0\n",
       "                 0  0.707106781186548\n",
       "\n",
       "[:, :, 2] =\n",
       "                  0  -0.707106781186548\n",
       " -0.707106781186548                   0\n",
       "\n",
       "[:, :, 3] =\n",
       "                   0  -0.707106781186548*I\n",
       " 0.707106781186548*I                     0\n",
       "\n",
       "[:, :, 4] =\n",
       " -0.707106781186548                  0\n",
       "                  0  0.707106781186548"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "σi=[sum(gi[μ,υ]*σ[υ,B,B1]*ϵ[B,A]*ϵ[B1,A1] for υ in 1:4, B in 1:2, B1 in 1:2) \n",
    "    for μ in 1:4, A in 1:2 , A1 in 1:2];\n",
    "\n",
    "[sum(gi[μ,υ]*σi[υ,A,B] for υ in 1:4) for A in 1:2 ,B in 1:2, μ in 1:4]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\\sigma_\\mu^{\\ \\ AA'}\\sigma^\\upsilon_{\\ \\ AA'}=-\\delta^\\upsilon_\\mu\\\\ \\sigma_\\mu^{\\ \\ AA'}\\sigma^\\mu_{\\ \\ BB'}=-\\delta^A_B\\delta^{A'}_{B'}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\[\\left[ \\begin{array}{rrrr}-1.0&0&0&0\\\\0&-1.0&0&0\\\\0&0&-1.0&0\\\\0&0&0&-1.0\\end{array}\\right]\\]"
      ],
      "text/plain": [
       "4×4 Array{Sym,2}:\n",
       " -1.00000000000000                  0                  0                  0\n",
       "                 0  -1.00000000000000                  0                  0\n",
       "                 0                  0  -1.00000000000000                  0\n",
       "                 0                  0                  0  -1.00000000000000"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[sum(σ[μ,A,A1]*σi[υ,A,A1] for A in 1:2, A1 in 1:2) for υ in 1:4, μ in 1:4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2×2×2×2 Array{Sym,4}:\n",
       "[:, :, 1, 1] =\n",
       " -2.22044604925031e-16  0\n",
       "                     0  0\n",
       "\n",
       "[:, :, 2, 1] =\n",
       "                     0  0\n",
       " -2.22044604925031e-16  0\n",
       "\n",
       "[:, :, 1, 2] =\n",
       " 0  -2.22044604925031e-16\n",
       " 0                      0\n",
       "\n",
       "[:, :, 2, 2] =\n",
       " 0                      0\n",
       " 0  -2.22044604925031e-16"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[sum(σ[μ,A,A1]*σi[μ,B,B1] for μ in 1:4)+δ[A,B]*δ[A1,B1] for A in 1:2, A1 in 1:2, B in 1:2, B1 in 1:2 ]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$g^{\\mu\\upsilon}\\sigma_\\mu^{\\ \\ AA'}\\sigma_\\upsilon^{BB'}-\\epsilon^{AB}\\epsilon^{\\ \\ A'B'}=0$\n",
    "\n",
    "这个直接验证很麻烦"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2×2×2×2 Array{Sym,4}:\n",
       "[:, :, 1, 1] =\n",
       " 0  0\n",
       " 0  0\n",
       "\n",
       "[:, :, 2, 1] =\n",
       "                     0  2.22044604925031e-16\n",
       " -2.22044604925031e-16                     0\n",
       "\n",
       "[:, :, 1, 2] =\n",
       "                    0  -2.22044604925031e-16\n",
       " 2.22044604925031e-16                      0\n",
       "\n",
       "[:, :, 2, 2] =\n",
       " 0  0\n",
       " 0  0"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[sum(gi[μ,υ]*σ[μ,A,A1]*σ[υ,B,B1] for μ in 1:4, υ in 1:4)+ϵ[A,B]*ϵ[A1,B1]\n",
    "        for A in 1:2, B in 1:2, A1 in 1:2, B1 in 1:2]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$\\sigma_\\mu^{\\ \\ AA'}\\sigma^\\upsilon_{\\ \\ AA'}=\\delta^\\upsilon_\\mu$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\[\\left[ \\begin{array}{rrrr}-1.0&0&0&0\\\\0&-1.0&0&0\\\\0&0&-1.0&0\\\\0&0&0&-1.0\\end{array}\\right]\\]"
      ],
      "text/plain": [
       "4×4 Array{Sym,2}:\n",
       " -1.00000000000000                  0                  0                  0\n",
       "                 0  -1.00000000000000                  0                  0\n",
       "                 0                  0  -1.00000000000000                  0\n",
       "                 0                  0                  0  -1.00000000000000"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[sum(sum(σ[μ,A,A1]*σi[υ,A,A1] for A in 1:2) for A1 in 1:2) for μ in 1:4, υ in 1:4]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$\\sigma_\\mu^{\\ \\ AA'}\\sigma^\\mu_{\\ \\ BB'}-\\delta^A_B\\delta^{A'}_{B'}$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2×2×2×2 Array{Sym,4}:\n",
       "[:, :, 1, 1] =\n",
       " -2.00000000000000                  0\n",
       "                 0  -2.00000000000000\n",
       "\n",
       "[:, :, 2, 1] =\n",
       " 0  0\n",
       " 0  0\n",
       "\n",
       "[:, :, 1, 2] =\n",
       " 0  0\n",
       " 0  0\n",
       "\n",
       "[:, :, 2, 2] =\n",
       " -2.00000000000000                  0\n",
       "                 0  -2.00000000000000"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[sum(σ[μ,A,A1]*σi[μ,B,B1] for μ in 1:4)-δ[A,B]*δ[A1,B1] for A in 1:2, B in 1:2, A1 in 1:2, B1 in 1:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Julia 1.5.2",
   "language": "julia",
   "name": "julia-1.5"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "1.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
